package com.qingzhuge.sms.controller;

import com.qingzhuge.controller.base.AbstractController;
import com.qingzhuge.core.annotation.security.Anonymous;
import com.qingzhuge.dto.response.BaseResponseDto;
import com.qingzhuge.dto.response.ResponseBodyDto;
import com.qingzhuge.sms.service.ISysSmsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author : zero.xiao
 * @description : 短信验证码
 * @date : 2018/12/29 0029 下午 19:36
 * @modified :
 * @since :
 */
@RestController
@RequestMapping({"/api","/api/sys/open"})
@Api(tags = "A短信验证码接口")
public class ApiSmsCodeController extends AbstractController {
    @Resource
    private ISysSmsService smsService;
    @Anonymous
    @PostMapping("{mobile}/code/register")
    @ApiOperation("注册验证码")
    public ResponseEntity<ResponseBodyDto<Object>> registerCode(@PathVariable String mobile) {
        BaseResponseDto response = smsService.registerCode(mobile);
        return returnSuccess(response.getResCode(), response.getResMessage());
    }

    @Anonymous
    @PostMapping("{mobile}/code/login")
    @ApiOperation("登录验证码")
    public ResponseEntity<ResponseBodyDto<Object>> loginCode(@PathVariable String mobile) {
        BaseResponseDto response = smsService.loginCode(mobile);
        return returnSuccess(response.getResCode(), response.getResMessage());
    }

    @Anonymous
    @PostMapping("{mobile}/code/resetPwd")
    @ApiOperation("重置密码验证码")
    public ResponseEntity<ResponseBodyDto<Object>> resetPwdCode(@PathVariable String mobile) {
        BaseResponseDto response = smsService.resetPwdCode(mobile);
        return returnSuccess(response.getResCode(), response.getResMessage());
    }
}
